import * as path from "path";
import {defineConfig} from "vite";
import react from "@vitejs/plugin-react";
import postCssPxToRem from "postcss-pxtorem";

export default defineConfig({
    plugins: [
        react({
            // lazy 去除 警告
            babel: {
                parserOpts: {
                    plugins: ["decorators-legacy"],
                },
            },
        }),
    ],
    assetsInclude: ["**/*.gltf"],
    resolve: {
        alias: [
            {
                find: "@",
                replacement: path.resolve(__dirname, "src"),
            },
        ],
    },
    css: {
        postcss: {
            plugins: [
                postCssPxToRem({
                    // 自适应，px>rem转换
                    rootValue: 75, // 75表示750设计稿，37.5表示375设计稿
                    propList: ["*"], // 需要转换的属性，这里选择全部都进行转换
                    exclude: "/node_modules", // 忽略包文件转换rem
                }),
            ],
        },
        preprocessorOptions: {
            less: {
                additionalData: `@import "${path.resolve(__dirname, "./src/assets/style/theme.less")}";`,
                javascriptEnabled: true,
            },
        },
    },
    server: {
        // host: "172.18.74.82",
        // host: "192.168.0.103"
        host: "127.0.0.1",
        port: 8082,
        proxy: {
            "/youquan": {
                target: "http://118.25.141.195:8089",
                changeOrigin: true,
            },
            "/api": {
                target: "http://admin.alinlearn.cn/service/youquan",
                changeOrigin: true,
                rewrite: path => path.replace(/^\/api/, ""),
            },
        },
    },
});
